package cycling.taxi.com.ui.fragment;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

import butterknife.ButterKnife;
import cycling.taxi.com.R;
import cycling.taxi.com.adapter.Adapter_GridView;
import cycling.taxi.com.adapter.Adapter_GridView_hot;
import cycling.taxi.com.dialog.AbOnItemClickListener;
import cycling.taxi.com.dialog.AbSlidingPlayView;
import cycling.taxi.com.ui.activity.DetailsActivity;
import cycling.taxi.com.utils.ToastUtil;

/**
 * 商场
 * Created by Administrator on 2017/4/20.
 */
public class StoreFrgt extends Fragment{

    //顶部标题栏
    private TextView tv_top_title;
    //分类的九宫格
    private GridView gridView_classify;
    //热门市场的九宫格
    private Adapter_GridView adapter_GridView_classify;
    private Adapter_GridView_hot adapter_GridView_hot;
    //首页轮播
    private AbSlidingPlayView viewPager;
    //扫一扫
    private ImageView iv_shao;
    // 分类九宫格的资源文件
    private int[] pic_path_classify = { R.drawable.e, R.drawable.b, R.drawable.c, R.drawable.d};
    /**存储首页轮播的界面*/
    private ArrayList<View> allListView;
    /**首页轮播的界面的资源*/
    private int[] resId = { R.drawable.viewpagera, R.drawable.viewpagerb, R.drawable.viewpagerc};

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        System.out.println("----商城");
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_store, null);
        ButterKnife.inject(this,view);
        initView(view);
        return view;
    }
    private void initView(View view) {
        iv_shao=(ImageView) view.findViewById(R.id.iv_shao);
        iv_shao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {

            }
        });
        tv_top_title=(TextView) view.findViewById(R.id.tv_top_title);
        tv_top_title.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {

            }
        });
        gridView_classify = (GridView) view.findViewById(R.id.my_gridview);
        gridView_classify.setSelector(new ColorDrawable(Color.TRANSPARENT));
        adapter_GridView_classify = new Adapter_GridView(getActivity(), pic_path_classify);
        gridView_classify.setAdapter(adapter_GridView_classify);
        viewPager = (AbSlidingPlayView) view.findViewById(R.id.viewPager_menu);
        //设置播放方式为顺序播放
        viewPager.setPlayType(1);
        //设置播放间隔时间
        viewPager.setSleepTime(3000);

        gridView_classify.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                //跳转到详情界面
              //  Intent intent = new Intent(getActivity(), DetailsActivity.class);
              //  startActivity(intent);
            }
        });


        initViewPager();
    }
    private void initViewPager() {

        if (allListView != null) {
            allListView.clear();
            allListView = null;
        }
        allListView = new ArrayList<View>();

        for (int i = 0; i < resId.length; i++) {
            //导入ViewPager的布局
            View view = LayoutInflater.from(getActivity()).inflate(R.layout.pic_item, null);
            ImageView imageView = (ImageView) view.findViewById(R.id.pic_item);
            imageView.setImageResource(resId[i]);
            allListView.add(view);
        }


        viewPager.addViews(allListView);
        //开始轮播
        viewPager.startPlay();
        viewPager.setOnItemClickListener(new AbOnItemClickListener() {
            @Override
            public void onClick(int position) {
                //跳转到详情界面
                Intent intent = new Intent(getActivity(), DetailsActivity.class);
                startActivity(intent);
            }
        });
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
